function init() {
  loadFriends();
}
function loadFriends() {
  var req = opensocial.newDataRequest();
  var params = {};
  params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] =
        [opensocial.Person.Field.CURRENT_LOCATION];
  
  req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER,
		params), 'viewer');
  req.add(req.newFetchPeopleRequest(opensocial.DataRequest.FilterType.HAS_APP,
		params), 'viewerFriends'); 
  req.send(onLoadFriends);
}

function onLoadFriends(data) {
  var viewer = data.get('viewer').getData();
  var viewerFriends = data.get('viewerFriends').getData();
  var count=0;
  alert(viewerFriends);
  html = new Array();
  html.push('<ul>');
  viewerFriends.each(function(person) {
  alert(person.getDisplayName());
  var address = person.getField(opensocial.Person.Field.CURRENT_LOCATION);
  var country = address.getField(opensocial.Address.Field.LOCALITY);
  alert(country);
  if(address!=null)
  {
  var country = address.getField(opensocial.Address.Field.LOCALITY);
  if((country.toString()).toUpperCase()=='MUMBAI'||(country.toString()).toUpperCase()=='BOMBAY')
    {
    html.push('<li>' +person.getDisplayName() + "</li>");
    count=count+1;
    }
    }
  });
  html.push('</ul>');
  var html2=new String("Number of friends from Mumbai are:");
  html2=html2+count;
  document.getElementById('numoffriends').innerHTML=html2;
  document.getElementById('friends').innerHTML = html.join('');
}